package handler;

import entity.Blog;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CustomBeanBlogListHandler implements ResultSetHandler<List<Blog>> {
    @Override
    public List<Blog> handle(ResultSet resultSet) throws SQLException {
        List<Blog> blogList = new ArrayList<>();
        while (resultSet.next()) {
            Blog blog = new Blog();
            blog.setId(resultSet.getInt("id"));
            java.sql.Date sqlDate = resultSet.getDate("actionTime");
            blog.setActionTime(sqlDate);
            blog.setAddress(resultSet.getString("address"));
            blog.setPeoples(resultSet.getString("peoples"));
            blog.setEvent(resultSet.getString("event"));
            blog.setTitle(resultSet.getString("title"));
            blogList.add(blog);
        }
        return blogList;
    }
}
